(function () {
    let init = echarts.init(document.querySelector('#system'));
    let option = {
        color: ["#00f2f1", "#ed3f35"],
        tooltip: {
            trigger: "axis",
            axisPointer: {
                // 坐标轴指示器，坐标轴触发有效
                type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        title: [
            {
                text: '未用内存', x: '10%', y: '80%', textStyle: {fontSize: 12, color: '#FFFFFF'},
                subtext: '18239', subtextStyle: {fontSize: 12, color: '#d21f1f'}
            },
            {
                text: '已用内存', x: '10%', y: '65%', textStyle: {fontSize: 12, color: '#FFFFFF'},
                subtext: '18239', subtextStyle: {fontSize: 12, color: '#d21f1f'}
            },
            {
                text: '未用硬盘', right: '10%', y: '80%', textStyle: {fontSize: 12, color: '#FFFFFF'},
                subtext: '18239', subtextStyle: {fontSize: 12, color: '#d21f1f'}
            },
            {
                text: '已用硬盘', right: '10%', y: '65%', textStyle: {fontSize: 12, color: '#FFFFFF'},
                subtext: '18239', subtextStyle: {fontSize: 12, color: '#d21f1f'}
            },
        ],
        series: [{
            type: 'gauge',
            radius: '50%',
            startAngle: 180,
            endAngle: 45,
            center: ['20%', '35%'],
            splitNumber: 5,
            axisLine: {
                lineStyle: {
                    width: 10,
                    color: [
                        [0.3, '#67e0e3'],
                        [0.7, '#37a2da'],
                        [1, '#fd666d']
                    ]
                }
            },
            pointer: {
                width: 2,
                itemStyle: {
                    color: 'auto'
                }
            },
            axisTick: {
                distance: -10,
                length: 8,
                lineStyle: {
                    color: '#fff',
                    width: 2
                }
            },
            splitLine: {
                distance: -10,
                length: 1,
                lineStyle: {
                    color: '#fff',
                    width: 4
                }
            },
            axisLabel: {
                color: 'auto',
                distance: 10,
                fontSize: 12
            },
            detail: {
                valueAnimation: true,
                formatter: '{value} %\n内存已使用',
                color: 'auto',
                textStyle: {
                    fontSize: 12
                }
            },
            data: [{
                value: 70
            }]
        }, {
            type: 'gauge',
            radius: '57%',
            center: ['50%', '40%'],
            axisLine: {
                lineStyle: {
                    width: 10,
                    color: [
                        [0.3, '#67e0e3'],
                        [0.7, '#37a2da'],
                        [1, '#fd666d']
                    ]
                }
            },
            splitNumber: 5,
            pointer: {
                itemStyle: {
                    color: 'auto'
                }
            },
            axisTick: {
                distance: -10,
                length: 8,
                lineStyle: {
                    color: '#fff',
                    width: 2
                }
            },
            splitLine: {
                distance: -10,
                length: 10,
                lineStyle: {
                    color: '#fff',
                    width: 4
                }
            },
            axisLabel: {
                color: 'auto',
                distance: 10,
                fontSize: 12
            },
            detail: {
                valueAnimation: true,
                formatter: '\n\n\n\n{value} %\ncpu使用',
                color: 'auto',
                textStyle: {
                    fontSize: 12
                }
            },
            data: [{
                value: 70
            }]
        }, {
            type: 'gauge',
            radius: '50%',
            startAngle: 140,
            endAngle: 0,
            center: ['80%', '35%'],
            axisLine: {
                lineStyle: {
                    width: 10,
                    color: [
                        [0.3, '#67e0e3'],
                        [0.7, '#37a2da'],
                        [1, '#fd666d']
                    ]
                }
            },
            splitNumber: 5,
            pointer: {
                width: 2,
                itemStyle: {
                    color: 'auto'
                }
            },
            axisTick: {
                distance: -10,
                length: 8,
                lineStyle: {
                    color: '#fff',
                    width: 2
                }
            },
            splitLine: {
                distance: -10,
                length: 1,
                lineStyle: {
                    color: '#fff',
                    width: 4
                }
            },
            axisLabel: {
                color: 'auto',
                distance: 10,
                fontSize: 12
            },
            detail: {
                valueAnimation: true,
                formatter: '{value} %\n硬盘使用',
                color: 'auto',
                textStyle: {
                    fontSize: 12
                }
            },
            data: [70]
        }]
    }

    let fontChange = function (baseSize) {
        for (let i = 0; i < 3; i++) {
            option.series[i].detail.textStyle.fontSize = Number((0.785 * baseSize).toFixed(0));
        }
        option.series[0].axisLabel.fontSize = Number((0.63 * baseSize).toFixed(0));
        option.series[1].axisLabel.fontSize = Number((0.785 * baseSize).toFixed(0));
        option.series[2].axisLabel.fontSize = Number((0.63 * baseSize).toFixed(0));
        for (let i = 0; i < 4; i++) {
            option.title[i].textStyle.fontSize = Number((0.785 * baseSize).toFixed(0));
            option.title[i].subtextStyle.fontSize = Number((0.785 * baseSize).toFixed(0));
        }

        return option;
    }
    resizeCallBack.push({chart: init, fontChange: fontChange})
    let updateFun = function ({cpu, ram, rom}, {ramRem, ramUsed, romRem, romUsed}) {
        option.series[0].data = [ram];
        option.series[1].data = [cpu]
        option.series[2].data = [rom]

        option.title[0].subtext = ramRem;
        option.title[1].subtext = ramUsed;
        option.title[2].subtext = romRem;
        option.title[3].subtext = romUsed;
        init.setOption(option);
    };
    if (charts1) {
        charts1['32'] = updateFun;
    }
})()